import PermissionButton from '@/components/BizButtons/PermissionButton';
import { UseActionControlReturnType } from '@/hooks/useActionControl';
import { EditOutlined } from '@ant-design/icons';
import React from 'react';

interface TableRowEditButtonProps {
  actionControl: UseActionControlReturnType;
  record: Record<string, any>;
  /** 所需权限,eg: ['monitor:online:forceLogout'], 传 [] 的视作不需要权限, 默认不需要权限 */
  permissionsRequired?: string[];
  /** 按钮的文字, 默认为空 即只显示图标 */
  buttonText?: string;
}

const TableRowEditButton: React.FC<TableRowEditButtonProps> = ({
  actionControl,
  record,
  permissionsRequired,
  buttonText,
}) => {
  return (
    <PermissionButton
      title={'编辑'}
      permissionsRequired={permissionsRequired}
      key="edit"
      icon={<EditOutlined />}
      type={'link'}
      loading={actionControl.loading.value}
      onClick={() => {
        actionControl.actions.openUpdateModal(record);
      }}
    >
      {buttonText}
    </PermissionButton>
  );
};

export default TableRowEditButton;
